package com.cyn.aframework.timedtask;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Test {

    public static void main(String[] args) {
        testTimerTask();
    }


    private static void testTimerTask() {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.SECOND,
                calendar.get(Calendar.SECOND) + 10);// 让日期加1
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SS").format(calendar.getTime()));
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                System.out.println("Hello, " + Thread.currentThread());
            }
        };
        timer.schedule(timerTask,0,1000);
    }

}
